import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
const app=getApp();
var ipUrl=app.globalData.ipUrl

var that;
const citys = {
  幼儿部: ['小班', '中班', '大班'],
  小学部: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级'],
  初中部: ['初一', '初二', '初三'],
};

Page({
  /**
   * 页面的初始数据
   */

  data: {
    //下拉框优先级
    butcolo:".mini-btn",
    butcolo1:"mini-btn",
    buxian:"mins",
    zhoyi:"mins",
    zhoer:"mins",
    zhosan:"mins",
    zhosi:"mins",
    zhowu:"mins",
    zholui:"mins",
    zhori:"mins",

    columns: [
      {
        values: Object.keys(citys),
        className: 'column6',
      },
      {
        values: citys['幼儿部'],
        className: 'column7',
        defaultIndex: 0,
      },
    ],

    bu:'一年级',
    bottom4: false,
    vaa4:"",


    xueke:'学科',
    bottom: false,
    vaa:"",

    xueqi:'学期',
    bottom2: false,
    vaa2:"",

    banci:'班次',
    bottom3: false,
    vaa3:"",


    //下拉框优先级
    a:5,
  },
  //年级部
  toggleBottomPopup8(e) {
    that.setData({
      bottom4: true
    });
  },
  toggleBottomPopup9(e) {
    that.setData({
      bottom4: false
    });
  },

  //筛选需要的下面
  xxdz:[],
  zzxxdz:null,
  zhujiang:null,
  fudao:null,
  itmes:[],
  zhu:[],
  xyuan:null,
  mainActiveIndex: 0,
  activeId: "",
  active: 0,
  max:"",
  checked: true,
  hasUserInfo: false,
  show: false,
  show1:false,
  show2:false,
  show3:false,

  onChange4(event) {
    that.setData({
      vaa4: event.detail.value
    });
  },
  onConfirm4(event) {
    console.log(event.detail.value);
    //获取默认学科,学期,班次
    wx.request({
      url: ipUrl+'/school/school/queryByGradesSchool?gradesId=9', //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var school = res.data;
        var discipline = new Array();//学科
        var semester = new Array();//学期
        var classes = new Array();//班次
        for(var i=0;i<school.length;i++){
          if(school[i].schooltype == 1001){//学科
            discipline.push(school[i].schoolname);
          }else if(school[i].schooltype == 1002){//学期
            semester.push(school[i].schoolname);
          }else if(school[i].schooltype == 1003){//班次
            classes.push(school[i].schoolname);
          }
        }
        that.setData({//给选择器(下拉框)赋值
          column1: discipline,//学科
          column2: semester,//学期
          column3: classes//班次
        })
      }
    });
    console.log(event.detail.value);
    //获取默认学科,学期,班次
    wx.request({
      url: ipUrl+'/school/school/queryByGradesSchool?gradesId=9', //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var school = res.data;
        var discipline = new Array();//学科
        var semester = new Array();//学期
        var classes = new Array();//班次
        console.log(school);
        for(var i=0;i<school.length;i++){
          console.log(school[i].schooltype+"|"+school[i].schoolname);
          if(school[i].schooltype == 1001){//学科
            discipline.push(school[i].schoolname);
          }else if(school[i].schooltype == 1002){//学期
            semester.push(school[i].schoolname);
          }else if(school[i].schooltype == 1003){//班次
            classes.push(school[i].schoolname);
          }
        }
        that.setData({//给选择器(下拉框)赋值
          column1: discipline,//学科
          column2: semester,//学期
          column3: classes//班次
        })
      }
    });
    that.setData({
      bu:event.detail.value[1],
      vaa4: event.detail.value,
    });
    that.setData({
      bottom4: false
    });
  },
  oncancel4(){
    that.setData({
      bottom4: false
    });
  },


 

    //学科
    toggleBottomPopup(e) {
      that.setData({
        bottom: true
      });
    },
    toggleBottomPopup2(e) {
      that.setData({
        bottom: false
      });
    },
    onChange15(event) {
      that.setData({
        vaa: event.detail.value
      });
    },
    onConfirm(event) {
      wx.request({
        url: ipUrl+'/school/school/queryByNameType?schooltype=1001&schoolname='+event.detail.value, //仅为示例，并非真实的接口地址
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          var schoolId = res.data;
        } 
      });
      if(event.detail.value == "其他"){
        that.setData({
          xueke: "学期",
          vaa: event.detail.value,
        });
      }else{
        that.setData({
          xueke: event.detail.value,
          vaa: event.detail.value,
        });
      }
      that.setData({
        bottom: false
      });
    },
    oncancel(){
      if(event.detail.value == "其他"){
        that.setData({
          xueke: "学期",
          vaa: event.detail.value,
        });
      }else{
        that.setData({
          xueke: event.detail.value,
          vaa: event.detail.value,
        });
      }
      that.setData({
        bottom: false
      });
    },




    //学期
    toggleBottomPopup22(e) {
      console.log(e)
      this.setData({
        bottom2: true
      });
    },
    toggleBottomPopup3(e) {
      console.log(e)
      this.setData({
        bottom2: false
      });
    },
    onChange2(event) {
      console.log("change", event.detail.value);
      this.setData({
        vaa2: event.detail.value
      });
    },
    onConfirm2(event) {
      wx.request({
        url: ipUrl+'/school/school/queryByNameType?schooltype=1002&schoolname='+event.detail.value, //仅为示例，并非真实的接口地址
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          var schoolId = res.data;
        }
      });
      if(event.detail.value == "其他"){
        that.setData({
          xueqi:"学科",
          vaa2: event.detail.value
        });
      }else{
        that.setData({
          xueqi:event.detail.value,
          vaa2: event.detail.value
        });
      }
      this.setData({
        bottom2: false
      });
    },
    oncancel2(){
      that.setData({
        bottom2: false
      });
    },




    //班次
    toggleBottomPopup4(e) {
      this.setData({
        bottom3: true
      });
    },
    toggleBottomPopup5(e) {
      this.setData({
        bottom3: false
      });
    },
    onChange3(event) {
      this.setData({
        vaa3: event.detail.value
      });
    },
    onConfirm3(event) {
      wx.request({
        url: ipUrl+'/school/school/queryByNameType?schooltype=1003&schoolname='+event.detail.value, //仅为示例，并非真实的接口地址
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          //获取班次id
          var schoolId = res.data;
        }
      });
      if(event.detail.value == "其他"){
        that.setData({
          banci:"班次",
          vaa3: event.detail.value
        });
      }else{
        that.setData({
          banci:event.detail.value,
        vaa3: event.detail.value
        });
      }
      this.setData({
        bottom3: false
      });
    },
    oncancel3(){
      that.setData({
        bottom3: false
      });
    },







  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    

    that=this;
    wx.request({
      url: ipUrl+'/course/course/queryAll', // 仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        that.setData({
          host:res.data
        });
      },fail(e){
        console.log("全部课程访问controller错误")
      }
    });

    //获取默认学科,学期,班次
    wx.request({
      //url: ipUrl+'/school/school/queryByGradesSchool?gradesId=9,
      url: ipUrl+'/school/school/queryAllGradesSchool',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var school = res.data;
        var discipline = new Array();//学科
        var semester = new Array();//学期
        var classes = new Array();//班次
        for(var i=0;i<school.length;i++){
          //console.log(school[i].schooltype+"|"+school[i].schoolname);
          if(school[i].schooltype == 1001){//学科
            discipline.push(school[i].schoolname);
          }else if(school[i].schooltype == 1002){//学期
            semester.push(school[i].schoolname);
          }else if(school[i].schooltype == 1003){//班次
            classes.push(school[i].schoolname);
          }
        }
        that.setData({//给选择器(下拉框)赋值
          column1: discipline,//学科
          column2: semester,//学期
          column3: classes//班次
        })
      }
    });

  },

  //课程详情
  detail:function(e){
    wx.navigateTo({
      url: '../kechengxiangqing/index?id='+e.target.id
    })
  },
 // teacherDetail老师详情
  teacherDetail(){
    console.log("老师详情")
    wx.navigateTo({
      url: ''
    })
  },

  //mine  我的
  mine(){
    console.log("我的")
    wx.navigateTo({
      url: ''
    })
  },

  //location 位置
  location(){
    console.log("位置")
    wx.navigateTo({
      url: ''
    })
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },









  //筛选查询课程需要的方法

  onChange1(event) {
    // event.detail 的值为当前选中项的索引

    wx.navigateTo({
      url: url.openUrl(event.detail),
    })
  },
  onClickShow() {
    this.setData({ show: true });
  },

  onClickHide() {
    this.setData({ show: false });
  },
  tiao(){

  },
  showPopup() {
    this.setData({ show: true });
    wx.request({
      url: 'http://localhost:8080/coursetype/coursetype/findAll', //仅为示例，并非真实的接口地址
      data: {
        x: '',
        y: ''
      },
      dataType:'json',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res)
        that.setData({
          courseType:res.data
        })

      }
    })
  },
  onClose() {
    this.setData({ show: false });
  },

// 查询上课地点
  showPopup1() {

    this.setData({ show1: true });

  },
  onClose1() {
    this.setData({ show1: false });

  },

  bef() {
    wx.request({
      url: 'http://localhost:8080/area/queryqujiedao', //仅为示例，并非真实的接口地址
      data: {
        id: 2
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data)
       that.setData({
        itmes:res.data,
        max:res.data.length

        })

      }
    })

  },

  bef1() {
    wx.request({
      url: 'http://localhost:8080/teacherdetails/teacherdetails/queryzhuTeacher', //仅为示例，并非真实的接口地址
      data: {
        postio:"主讲老师"
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var itemLists = [];  //item数组
        for(var i=0;i<res.data.data.length;i++){
          itemLists.push(res.data.data[i].kind);
          console.log(res.data.data[i])
        }

       that.setData({
          zhu:res.data.data,
          kind:itemLists
        })

      }
    })






  },
  bef2() {
    wx.request({
      url: 'http://localhost:8080/teacherdetails/teacherdetails/queryzhuTeacher', //仅为示例，并非真实的接口地址
      data: {
        postio:"辅导老师"
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        var itemLists = [];  //item数组
        for(var i=0;i<res.data.data.length;i++){
          itemLists.push(res.data.data[i].kind);
          console.log(res.data.data[i])
        }

       that.setData({
          zhu:res.data.data,
          kind:itemLists
        })

      }
    })



  },


//查询主讲老师
  showPopup2() {
    this.setData({ show2: true });

  },
  onClose2() {
    this.setData({ show2: false });
  },

  showPopup3() {
    this.setData({ show3: true });

    wx.request({
      url: 'http://localhost:8080/teacherdetails/teacherdetails/queryzhuTeacher', //仅为示例，并非真实的接口地址
      data: {
        postio:"辅导老师"
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data)
        // that.setData({
        //   itmes:res.data
        // })

      }
    })
  },
  onClose3() {
    this.setData({ show3: false });
  },
  pp(cc){
    var $this = this;
    console.log(cc.currentTarget.dataset.gid);
    that.setData({
    show2: false,
      zhujiang:cc.currentTarget.dataset.gid
    })

  },


  xxdzff(cc){
    var $this = this;
    console.log(cc.currentTarget.dataset.gid);
    that.setData({
    show1: false,
      zzxxdz:cc.currentTarget.dataset.gid
    })
  
  },
  ppp(ccc){
    var $this = this;
    console.log(ccc.currentTarget.dataset.gid);
    that.setData({
    show3: false,
    fudao:ccc.currentTarget.dataset.gi
    })



  },




    //作为查询上课地点的组件
    onClickNav({ detail = {} }) {
      this.setData({
        mainActiveIndex: detail.index || 0,
      });
    },

    onClickItem({ detail = {} }) {

      const activeId = this.data.activeId === detail.id ? null : detail.id;
      this.setData({ activeId 
      });
      console.log(activeId)
//根据接到去查询详细地址
wx.request({
  url: 'http://localhost:8080/position/position/queryaAddressId', //仅为示例，并非真实的接口地址
  data: {
    id:activeId
  },
  header: {
    'content-type': 'application/json' // 默认值
  },
  success (res) {
    console.log(res.data.data[0].address)
 
     that.setData({
       xxdz:res.data.data
     })

  }
}) 
    },

    butcolor(){
      that.setData({
        butcolo:"mini-btn1",
        butcolo1:"mini-btn"
      })
    },
    butcolor1(){
      that.setData({
        butcolo:"mini-btn",
        butcolo1:"mini-btn1"
      })
    },



    bxian(){
    that.setData({
        buxian:"minss",
        zhoyi:"mins",
        zhoer:"mins",
        zhosan:"mins",
        zhosi:"mins",
        zhowu:"mins",
        zholui:"mins",
        zhori:"mins",
      })
    },

    zyi(){
      that.setData({
          zhoyi:"minss",
          buxian:"mins",
          zhoer:"mins",
          zhosan:"mins",
          zhosi:"mins",
          zhowu:"mins",
          zholui:"mins",
          zhori:"mins",
        })
      },
       zer(){
        that.setData({
          zhoer:"minss",
          buxian:"mins",
          zhoyi:"mins",
          zhosan:"mins",
          zhosi:"mins",
          zhowu:"mins",
          zholui:"mins",
          zhori:"mins",
          })

        },

        zsan(){
          that.setData({
            zhosan:"minss",
            buxian:"mins",
            zhoyi:"mins",
            zhoer:"mins",
            zhosi:"mins",
            zhowu:"mins",
            zholui:"mins",
            zhori:"mins",

            })

          },
          zsi(){
            that.setData({
              zhosi:"minss",
              buxian:"mins",
              zhoyi:"mins",
              zhoer:"mins",
              zhosan:"mins",
              zhowu:"mins",
              zholui:"mins",
              zhori:"mins",
              })

            },
            zwu(){
              that.setData({
                zhowu:"minss",
                buxian:"mins",
                zhoyi:"mins",
                zhoer:"mins",
                zhosan:"mins",
                zhosi:"mins",
                zholui:"mins",
                zhori:"mins",
                })

              },

              zliu(){
                that.setData({
                  zholui:"minss",
                  buxian:"mins",
                  zhoyi:"mins",
                  zhoer:"mins",
                  zhosan:"mins",
                  zhosi:"mins",
                  zhowu:"mins",
                  zhori:"mins",

                  })

                },
                zri(){
                  that.setData({
                    zhori:"minss",
                    buxian:"mins",
                    zhoyi:"mins",
                    zhoer:"mins",
                    zhosan:"mins",
                    zhosi:"mins",
                    zhowu:"mins",
                    zholui:"mins",
                    })

                  },


})